問題の説明
plumbum: stdin に変数を送信する方法は? (plumbum: How to send a variable to stdin?)
私は現在:
(local['echo'][var] | sth)()
これは洗練されておらず、非効率的です。
リファレンスソリューション
方法 1:
I found the solution in the plumbum documentation:
You can use the shift‑left operator <<
.
from plumbum import local
if __name__ == '__main__':
var = "some text in a python variable"
sth = local["cat"]
x = (local['echo'][var] | sth)()
print(x)
print("alternative:")
x = (sth << var)()
print(x)
(by HappyFace、Lydia van Dyke)